<?php

namespace App\Http\Resources\Activity\B;

use App\Http\Resources\BaseResource;
use App\Models\Activity\ActivityModel;
use Illuminate\Http\Request;

class ActivityDetailResource extends BaseResource
{
    /**
     * Transform the resource into an array.
     *
     * @param Request $request
     * @return array
     */
    public function toArray($request): array
    {
        return [
            "id"                       => $this->id,
            "name"                     => $this->name,
            "activityType"             => $this->activityType,
            "activityTypeText"         => ActivityModel::ACTIVITY_TYPE_TEXT[$this->activityType] ?? "",
            "shopType"                 => $this->shopType,
            "shopTypeText"             => ActivityModel::SHOP_TYPE_TEXT[$this->shopType] ?? "",
            "joinShopIds"              => jsonToArr($this->joinShopIds, []),
            "expireType"               => $this->expireType,
            "expireTypeText"           => ActivityModel::EXPIRE_TYPE_TEXT[$this->expireType] ?? "",
            "startTime"                => formatDate($this->startTime, ""),
            "endTime"                  => formatDate($this->endTime, ""),
            "joinRestrict"             => collect(jsonToArr($this->joinRestrict, []))->map(function ($v, $key) {
                return [
                    "val" => $v,
                    "key" => $key
                ];
            })->values()->where("val", "=", 1)->pluck("key")->toArray(),
            "blackShopIds"             => jsonToArr($this->blackShopIds, []),
            "whiteShopIds"             => jsonToArr($this->whiteShopIds, []),
            "feedbackExampleImages"    => jsonToArr($this->feedbackExampleImages, []),
            "superScreenSwitch"        => $this->superScreenSwitch,
            "popUpTitle"               => $this->popUpTitle,
            "popUpContent"             => $this->popUpContent,
            "superScreenStartTime"     => formatDate($this->superScreenStartTime, ""),
            "superScreenEndTime"       => formatDate($this->superScreenEndTime, ""),
            "superScreenBeforeContent" => $this->superScreenBeforeContent,
            "superScreenAfterContent"  => $this->superScreenAfterContent,
            "detail"                   => $this->detail,
            "remark"                   => $this->remark,
            "feedbackImgSwitch"        => $this->feedbackImgSwitch,
            "remindSwitch"             => $this->remindSwitch,
            "remindStartTime"          => formatDate($this->remindStartTime, ""),
            "remindEndTime"            => formatDate($this->remindEndTime, ""),
            "systemNotifyCenterId"     => $this->systemNotifyCenterId,
            "remindDailyTime"          => $this->remindDailyTime,
            "remindCycle"              => jsonToArr($this->remindCycle, []),
            "status"                   => $this->status,
            "statusText"               => ActivityModel::STATUS_TEXT[$this->status] ?? "",
            "actions"                  => ActivityActionDetailResource::collection($this->shopActionRel),
            "superScreenFrequency"     => $this->superScreenFrequency,
            "superScreenFrequencyText" => ActivityModel::SUPER_SCREEN_FREQUENCY_TEXT[$this->superScreenFrequency] ?? "",
        ];
    }
}
